/******************************************************************************/
/*                                                                            */
/*  Copyright (c) 2009: ngi-central.org                                       */
/*  All rights reserved.                                                      */
/*                                                                            */
/******************************************************************************/


#include <boost/test/unit_test.hpp>

#include "..\..\include\sgl\polygon.h"

BOOST_AUTO_TEST_SUITE( polygon2d )


BOOST_AUTO_TEST_CASE( polygon2d__default_constructor )
{
	sgl::polygon<2> a;

	BOOST_CHECK( a.size() == 0 );

	sgl::polygon<2> b(
		sgl::quadrilateral<2>(
			sgl::point<2>(1, 2),
			sgl::point<2>(3, 4),
			sgl::point<2>(5, 6),
			sgl::point<2>(7, 8)));
	
	BOOST_CHECK( b[0][0] == 1 );
	BOOST_CHECK( b[0][1] == 2 );
	BOOST_CHECK( b[1][0] == 3 );
	BOOST_CHECK( b[1][1] == 4 );
	BOOST_CHECK( b[2][0] == 5 );
	BOOST_CHECK( b[2][1] == 6 );
	BOOST_CHECK( b[3][0] == 7 );
	BOOST_CHECK( b[3][1] == 8 );
}

BOOST_AUTO_TEST_CASE( polygon2d__copy_constructor )
{
	sgl::polygon<2> a(
		sgl::polygon<2>(
			sgl::quadrilateral<2>(
				sgl::point<2>(1, 2),
				sgl::point<2>(3, 4),
				sgl::point<2>(5, 6),
				sgl::point<2>(7, 8))));

	BOOST_CHECK( a[0][0] == 1 );
	BOOST_CHECK( a[0][1] == 2 );
	BOOST_CHECK( a[1][0] == 3 );
	BOOST_CHECK( a[1][1] == 4 );
	BOOST_CHECK( a[2][0] == 5 );
	BOOST_CHECK( a[2][1] == 6 );
	BOOST_CHECK( a[3][0] == 7 );
	BOOST_CHECK( a[3][1] == 8 );
}

BOOST_AUTO_TEST_CASE( polygon2d__copy_assignment )
{
	sgl::polygon<2> a(
		sgl::polygon<2>(
			sgl::quadrilateral<2>(
				sgl::point<2>(1, 2),
				sgl::point<2>(3, 4),
				sgl::point<2>(5, 6),
				sgl::point<2>(7, 8))));

	BOOST_CHECK( a[0][0] == 1 );
	BOOST_CHECK( a[0][1] == 2 );
	BOOST_CHECK( a[1][0] == 3 );
	BOOST_CHECK( a[1][1] == 4 );
	BOOST_CHECK( a[2][0] == 5 );
	BOOST_CHECK( a[2][1] == 6 );
	BOOST_CHECK( a[3][0] == 7 );
	BOOST_CHECK( a[3][1] == 8 );
}

BOOST_AUTO_TEST_CASE( polygon2d__swap )
{
	sgl::polygon<2> a(
		sgl::polygon<2>(
			sgl::quadrilateral<2>(
				sgl::point<2>(1, 2),
				sgl::point<2>(3, 4),
				sgl::point<2>(5, 6),
				sgl::point<2>(7, 8))));
	sgl::polygon<2> b;

	a.swap(b);

	BOOST_CHECK( a.size() == 0 );
	BOOST_CHECK( b[0][0] == 1 );
	BOOST_CHECK( b[0][1] == 2 );
	BOOST_CHECK( b[1][0] == 3 );
	BOOST_CHECK( b[1][1] == 4 );
	BOOST_CHECK( b[2][0] == 5 );
	BOOST_CHECK( b[2][1] == 6 );
	BOOST_CHECK( b[3][0] == 7 );
	BOOST_CHECK( b[3][1] == 8 );

	b.swap(a);

	BOOST_CHECK( a[0][0] == 1 );
	BOOST_CHECK( a[0][1] == 2 );
	BOOST_CHECK( a[1][0] == 3 );
	BOOST_CHECK( a[1][1] == 4 );
	BOOST_CHECK( a[2][0] == 5 );
	BOOST_CHECK( a[2][1] == 6 );
	BOOST_CHECK( a[3][0] == 7 );
	BOOST_CHECK( a[3][1] == 8 );
	BOOST_CHECK( b.size() == 0 );
}

BOOST_AUTO_TEST_CASE( polygon2d__geometric_type )
{
	sgl::polygon<2> a;

	BOOST_CHECK( a.type() == sgl::geometric_primitive<>::polygon );
}

BOOST_AUTO_TEST_CASE( polygon2d__dimensions )
{
	sgl::polygon<2> a;

	BOOST_CHECK( a.dimensions() == 2 );
}

BOOST_AUTO_TEST_CASE( polygon2d__operator_equality )
{
	sgl::polygon<2> a;
	sgl::polygon<2> b;

	BOOST_CHECK( a == b );

	sgl::polygon<2> c(
		sgl::quadrilateral<2>(
			sgl::point<2>(1, 2), sgl::point<2>(3, 4), 
			sgl::point<2>(5, 6), sgl::point<2>(7, 8)));
	sgl::polygon<2> d(
		sgl::quadrilateral<2>(
			sgl::point<2>(1, 2), sgl::point<2>(3, 4), 
			sgl::point<2>(5, 6), sgl::point<2>(7, 8)));

	BOOST_CHECK( c == d );
}

BOOST_AUTO_TEST_CASE( polygon2d__operator_inequality )
{
	sgl::polygon<2> a;
	sgl::polygon<2> b(
		sgl::quadrilateral<2>(
			sgl::point<2>(1, 2), sgl::point<2>(3, 4), 
			sgl::point<2>(5, 6), sgl::point<2>(7, 8)));

	BOOST_CHECK( a != b );
}

BOOST_AUTO_TEST_CASE( polygon2d__addition )
{
	sgl::polygon<2> a(
		sgl::polygon<2>(
			sgl::quadrilateral<2>(
				sgl::point<2>(1, 2),
				sgl::point<2>(3, 4),
				sgl::point<2>(5, 6),
				sgl::point<2>(7, 8))));
	a += sgl::vector<2>(1, 2);

	BOOST_CHECK( a[0][0] == 2 );
	BOOST_CHECK( a[0][1] == 4 );
	BOOST_CHECK( a[1][0] == 4 );
	BOOST_CHECK( a[1][1] == 6 );
	BOOST_CHECK( a[2][0] == 6 );
	BOOST_CHECK( a[2][1] == 8 );
	BOOST_CHECK( a[3][0] == 8 );
	BOOST_CHECK( a[3][1] == 10 );

	sgl::polygon<2> b(
		sgl::quadrilateral<2>(
			sgl::point<2>(0, 0), sgl::point<2>(0, 0), 
			sgl::point<2>(0, 0), sgl::point<2>(0, 0)));
	sgl::vector<2> c(1, 2);
	sgl::polygon<2> d = b+c;

	BOOST_CHECK( d[0][0] == 1 );
	BOOST_CHECK( d[0][1] == 2 );
	BOOST_CHECK( d[1][0] == 1 );
	BOOST_CHECK( d[1][1] == 2 );
	BOOST_CHECK( d[2][0] == 1 );
	BOOST_CHECK( d[2][1] == 2 );
	BOOST_CHECK( d[3][0] == 1 );
	BOOST_CHECK( d[3][1] == 2 );

	sgl::polygon<2> e = c+b;

	BOOST_CHECK( e[0][0] == 1 );
	BOOST_CHECK( e[0][1] == 2 );
	BOOST_CHECK( e[1][0] == 1 );
	BOOST_CHECK( e[1][1] == 2 );
	BOOST_CHECK( e[2][0] == 1 );
	BOOST_CHECK( e[2][1] == 2 );
	BOOST_CHECK( e[3][0] == 1 );
	BOOST_CHECK( e[3][1] == 2 );
}

BOOST_AUTO_TEST_CASE( polygon2d__subtraction )
{
	sgl::polygon<2> a(
		sgl::polygon<2>(
			sgl::quadrilateral<2>(
				sgl::point<2>(1, 2),
				sgl::point<2>(3, 4),
				sgl::point<2>(5, 6),
				sgl::point<2>(7, 8))));
	a -= sgl::vector<2>(1, 2);

	BOOST_CHECK( a[0][0] == 0 );
	BOOST_CHECK( a[0][1] == 0 );
	BOOST_CHECK( a[1][0] == 2 );
	BOOST_CHECK( a[1][1] == 2 );
	BOOST_CHECK( a[2][0] == 4 );
	BOOST_CHECK( a[2][1] == 4 );
	BOOST_CHECK( a[3][0] == 6 );
	BOOST_CHECK( a[3][1] == 6 );

	sgl::polygon<2> b(
		sgl::quadrilateral<2>(
			sgl::point<2>(0, 0), sgl::point<2>(0, 0), 
			sgl::point<2>(0, 0), sgl::point<2>(0, 0)));
	sgl::vector<2> c(1, 2);
	sgl::polygon<2> d = b-c;

	BOOST_CHECK( d[0][0] == -1 );
	BOOST_CHECK( d[0][1] == -2 );
	BOOST_CHECK( d[1][0] == -1 );
	BOOST_CHECK( d[1][1] == -2 );
	BOOST_CHECK( d[2][0] == -1 );
	BOOST_CHECK( d[2][1] == -2 );
	BOOST_CHECK( d[3][0] == -1 );
	BOOST_CHECK( d[3][1] == -2 );
}

BOOST_AUTO_TEST_SUITE_END()

